package com.ruoyi.web.controller.mall.orderBack.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.controller.mall.orderBack.domain.OrderBack;
import com.ruoyi.web.controller.mall.orderBack.service.IOrderBackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 退货记录Controller
 * 
 * @author ruoyi
 * @date 2021-01-18
 */
@Controller
@RequestMapping("/mall/orderBack")
public class OrderBackController extends BaseController
{
    private String prefix = "mall/orderBack";

    @Autowired
    private IOrderBackService orderBackService;

//    @RequiresPermissions("mall:orderBack:view")
    @GetMapping()
    public String orderBack()
    {
        return prefix + "/orderBack";
    }

    /**
     * 查询退货记录列表
     */
//    @RequiresPermissions("mall:orderBack:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrderBack orderBack)
    {
        startPage();
        List<OrderBack> list = orderBackService.selectOrderBackList(orderBack);
        return getDataTable(list);
    }

    /**
     * 导出退货记录列表
     */
//    @RequiresPermissions("mall:orderBack:export")
    @Log(title = "退货记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrderBack orderBack)
    {
        List<OrderBack> list = orderBackService.selectOrderBackList(orderBack);
        ExcelUtil<OrderBack> util = new ExcelUtil<OrderBack>(OrderBack.class);
        return util.exportExcel(list, "orderBack");
    }

    /**
     * 新增退货记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存退货记录
     */
//    @RequiresPermissions("mall:orderBack:add")
    @Log(title = "退货记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrderBack orderBack)
    {
        return toAjax(orderBackService.insertOrderBack(orderBack));
    }

    /**
     * 修改退货记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        OrderBack orderBack = orderBackService.selectOrderBackById(id);
        mmap.put("orderBack", orderBack);
        return prefix + "/edit";
    }

    /**
     * 修改保存退货记录
     */
//    @RequiresPermissions("mall:orderBack:edit")
    @Log(title = "退货记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrderBack orderBack)
    {
        return toAjax(orderBackService.updateOrderBack(orderBack));
    }

    /**
     * 删除退货记录
     */
//    @RequiresPermissions("mall:orderBack:remove")
    @Log(title = "退货记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String[] ids)
    {
        return toAjax(orderBackService.deleteOrderBackByIds(ids));
    }
}
